using DataScripter.Excel.Formulas;

namespace DataScripter.Excel.Table
{
	internal class TableColumnReference : Formula
	{
		public TableColumn ReferredColumn { get; set; }
		public int RowDiff { get; set; }

		public TableColumnReference(TableColumn tableColumn)
			: this(tableColumn, 0)
		{ }

		public TableColumnReference(TableColumn tableColumn, int rowDiff)
		{
			ReferredColumn = tableColumn;
			RowDiff = rowDiff;
		}

		public override string Resolve(ICell current)
		{
			int destinationColumnExcelNumbering = ReferredColumn.Index + ReferredColumn.Table.StartCell.Column - ReferredColumn.Table.NumberOfEmptyColumns;
			int sourceColumnExcelNumbering = current.Column;
			int colDiff = destinationColumnExcelNumbering - sourceColumnExcelNumbering;
			return current.GetDiff(RowDiff, colDiff).CellReference;
		}
	}
}